<?




//display section in functie de id (daca acesta este 0 atunci se adauga):



function display($idd)
{
	//incarc sql cu valori pentru titlu:
	$searchTitles = returnQuery("select * from document_body where type = 'Title' and id_doc='".$idd."' order by orderT",$dbh);
	$searchSubtitles = returnQuery("select * from document_body where type in ('Title','Subtitle') and id_doc='".$idd."' order by orderT, orderS",$dbh);
	
	$i = 0; 
	$arrTitles = array(); 
	$arrTitlesID = array();
	while ($row = mysql_fetch_array($searchTitles)) { 
		$arrTitles[$i] = $row["content"]; 
		$arrTitlesID[$i] = $row["id"];
		$i++; 
	}
	$j = 0; 
	$arrSubtitles = array(); 
	$arrSubtitlesID = array(); 
	$arrSubtitlesType = array();
	while ($row = mysql_fetch_array($searchSubtitles)) { 
		$arrSubtitles[$j] = $row["content"]; 
		$arrSubtitlesID[$j] = $row["id"];
		$arrSubtitlesType[$j] = $row["type"];
		$j++; 
	} 
	?>
	
	<!-- SCRIPT PENTRU POPULAREA COMBOXURILOR -->
	<script type="text/javascript"> 
		arrTitle = new Array(); 
		arrTitleID = new Array();
		<?php 
		for($i=0;$i<count($arrTitles); $i++){ 
			echo "arrTitle[$i]='".$arrTitles[$i]."';\n"; 
			echo "arrTitleID[$i]='".$arrTitlesID[$i]."';\n";
		} 
		?> 
		arrSubtitle = new Array(); 
		arrSubtitleID = new Array(); 
		arrSubtitleType = new Array();
		<?php 
		for($i=0;$i<count($arrSubtitles); $i++){ 
			echo "arrSubtitle[$i]='".$arrSubtitles[$i]."';\n"; 
			echo "arrSubtitleID[$i]='".$arrSubtitlesID[$i]."';\n"; 
			echo "arrSubtitleType[$i]='".$arrSubtitlesType[$i]."';\n"; 
		} 
		?> 

	function umple(idx) {
		var f=document.add_title_form;
		var scrie;
		if (idx==0) 
		{
			//alert(arrSubtitle[0]);
			f.sel_place.options.length=null;
			f.sel_place.options[0] = new Option('-- As first Title --', 0);
			for(var i=0; i<arrTitle.length; i++) {
				f.sel_place.options[i+1] = new Option(arrTitle[i],arrTitleID[i]);
			}
			f.sel_place.options[0].selected = true;
		} 
		else 
		{
			f.sel_place.options.length=null;
			
			for(var i=0; i<arrSubtitle.length; i++) {
				if (arrSubtitleType[i]=='Title') {
					scrie = 'T: '+arrSubtitle[i];
				} else {
					scrie = ' '+'S: '+arrSubtitle[i];
				}
				
				f.sel_place.options[i] = new Option(scrie,arrSubtitleID[i]);
			}
			f.sel_place.options[0].selected = true;
		}
	}
	</script>

	

	<body onLoad="umple(0);">
	<form action="" name="add_title_form" method="POST">
    <br> <div align="center">
	<table width="90%">
	<tr><td bgcolor="#8ED9F9" width="30%">Type</td><td bgcolor="#8ED9F9"><select name="sel_type" style="width:100%" onChange="umple(this.selectedIndex)">
											<option value="Title">Title</option>
											<option value="Subtitle">Subtitle</option></select></td></tr>
	<tr><td bgcolor="#8ED9F9">Place after</td><td bgcolor="#8ED9F9"><select name="sel_place" style="width:100%"></select></td></tr>
	
	<tr><td bgcolor="#8ED9F9">With Content</td><td bgcolor="#8ED9F9"><input type="checkbox" name="content" value="true" checked></td></tr>
	
  
    <tr><td bgcolor="#8ED9F9"><input type="submit" name="qr_add" value="Apply" ></td>
	<td align="right" bgcolor="#8ED9F9"><input type="submit" name="qr_cancel" value="Cancel" align="left"></td></tr>
	</table>
	</div>
	</form>
	</body>
	<?
	
	
}
?>